package org.apache.sad.core.framework.jaxrpc;

public class ServiceContextHandler {
    private static ThreadLocal<ServiceContext> contextCarrier = new ThreadLocal<ServiceContext>() {
        protected synchronized ServiceContext initialValue() {
            return new ServiceContext();
        }
    };

    private static ServiceContextHandler handler = new ServiceContextHandler();

    private ServiceContextHandler() {
    }

    public static ServiceContextHandler getInstance() {
        return handler;
    }

    public ServiceContext getServiceContext() {
        return contextCarrier.get();
    }
    
    public void setServiceContext(ServiceContext context) {
    	contextCarrier.set(context);
    }
    
    public void removeServiceContext() {
    	contextCarrier.get().clear();
    	contextCarrier.remove();
    }
}